package com.wuyancheng.interceptor;

import com.wuyancheng.cache.LoginCache;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class LoginIntercepetor implements HandlerInterceptor{

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //用户默认为admin，校验已经登陆的用户中是否已经有admin
        if(LoginCache.checkPermission("admin")){
            return true;
        }
        //admin，没有登陆，重定向到登陆页面
        response.sendRedirect("/index.jsp");
        return false;
    }
}
